<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>业务模板管理</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var type = "${param.type}";
    var dType = "${param.dType}";
    var isTongguanYth = "${param.isTongguanYth}";
    var isAgent="${param.isAgent}";
    var formSetting = {
        title: "查询业务模板信息",
        module: 'query',
        columns: [{
            index: "MODEL_NAME",
            name: "model_name",
            label: "名称"
        }, {
            index: "TYPE",
            name: "type",
            label: "类型",
            type: "dropdown",
            data: [["报关", "D"], ["拖车", "C"]]
        }, {
            index: "T_SYS_USER.U_NAME",
            name: "T_SYS_USER.U_NAME",
            label: "保存人"
        }, {
            index: "SAVE_MODEL_TIME",
            name: "save_model_time",
            label: "保存时间从",
            type: "date",
            op: "ge"
        }, {
            index: "SAVE_MODEL_TIME",
            name: "save_model_time",
            label: "到",
            type: "date",
            op: "le"
        }],
        buttons: {
            custom: [
                {
                    id: "updatebtn0",
                    value: "使用模板",
                    click: function () {
                        /* var id = $("#businessModelDataGrid").jqGrid("getGridParam",
                         "selrow");
                         if(id) {
                         // 							window.location.href="declaration-bizView?id="+id;
                         window.location.href="business-checkDetail?id="+id+"&singleType=D&checkDetail=T&identification=list";
                         } else {
                         jw.alert("请点击需要操作的数据!");
                         } */
                        var selectedRowId = $("#businessModelDataGrid").getGridParam("selrow");
                        if (selectedRowId) {
                            var selectedRow = $("#businessModelDataGrid").getRowData(selectedRowId);
                            var compareTemplateTip=layer.confirm('对旧数据进行修改时，被修改过的数据会显示亮色底纹进行区分显示', {
                                btn: ['确定'] //按钮
                            }, function(){
                                parent.loadBizFromHistoryData(selectedRow.business_id, selectedRow.id,
                                                              "all",
                                                              selectedRow.is_record_info, "3.0",isTongguanYth,type,dType,isAgent);
                                layer.close(compareTemplateTip);
                            });

                            jw.close();

                        }
                        else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "delbtn",
                    value: "删除模板",
                    click: function () {
                        var selectedIds = $("#businessModelDataGrid").jqGrid("getGridParam",
                                                                             "selrow");
                        var rowDatas = $("#businessModelDataGrid").jqGrid('getRowData',
                                                                          selectedIds);
                        var type = rowDatas["type"];
                        if (type == "报关") {
                            type = "D";
                        } else if (type == "拖车") {
                            type = "C";
                        }
                        if (selectedIds) {
                            if (confirm("确定要删除选择的项?")) {
                                var data = "id=" + selectedIds + "&type=" + type;
                                $.ajax({
                                           url: "model-delete",
                                           dataType: "json",
                                           data: data,
                                           cache: false,
                                           success: function (data) {
                                               var msg = $.parseJSON(data.msg);
                                               if (msg.state == "1") {
                                                   $("#businessModelDataGrid").jqGrid(
                                                           "setGridParam",
                                                           {
                                                               search: true
                                                               // 将jqGrid的search选项设为true
                                                           }).trigger("reloadGrid", [{
                                                       page: 1
                                                   }]);
                                                   jw.alert(msg.msg);
                                               } else {
                                                   jw.alert(msg.msg);

                                               }
                                           }
                                       });
                            }
                        } else {
                            jw.alert("请选择需要删除的数据!");
                        }
                    }
                }
            ]
        },
        grid: {
            id: "businessModelDataGrid",
            title: "查询结果",
            autowidth: false,
            url: "model-findList?type=D&dType=" + dType + "&isTongguanYth="+isTongguanYth+"&isAgent="+isAgent,
            //multiselect : true,
            /* postData : {
             "pid" : pid
             }, */
            colModel: [{
                index: "ID",
                name: "id",
                label: "id",
                hidden: true
            }, {
                index: "business_id",
                name: "business_id",
                label: "业务编号",
                hidden: true
            }, {
                index: "MODEL_NAME",
                name: "model_name",
                width: 200,
                label: "模板名称"
            }, {
                index: "SAVE_MODEL_TIME",
                name: "save_model_time",
                width: 200,
                label: "保存模板时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "SAVE_MODEL_PERSON",
                name: "save_model_person",
                width: 200,
                label: "模板保存人"
            }, {
                index: "TYPE",
                name: "type",
                label: "模板类型",
                formatter: function (cellvalue, options, rowObject) {
                    if (cellvalue == "D") {
                        return "报关";
                    } else if (cellvalue == "C") {
                        return "拖车";
                    }
                }
            }, {
                index: "IS_RECORD_INFO",
                name: "is_record_info",
                label: "是否手册",
                hidden: true
            }],
            loadComplete: function (data) {

            },
            ondblClickRow: function () {
                var selectedRowId = $("#businessModelDataGrid").getGridParam("selrow");
                if (selectedRowId) {
                    var selectedRow = $("#businessModelDataGrid").getRowData(selectedRowId);
                    parent.loadBizFromHistoryData(selectedRow.business_id, selectedRow.id, "all",
                                                  selectedRow.is_record_info, "3.0",isTongguanYth,type,dType);
//                    jw.close();
                }
            }
        }
    };
    $(document).ready(function () {
        $("#businessModelDataTable").mrdForm(formSetting);
        var main = parent.$("#layui-layer-iframe1");
        main.height(580);
    });
    /*
     function setGridCell(i, name, value) {
     var ids = $("#declarationsDataGrid").getDataIDs();
     $("#declarationsDataGrid").setCell(ids[i], name, value);
     }

     function findBizResult(bizId) {
     jw.dialog({iframe:'declaration-findBizResult?id='+bizId});
     }

     function findBizState(i, colName, bizId) {
     var data = "id="+bizId;
     $.ajax({
     url : "declaration-findBizState",
     cache: false,
     dataType : "json",
     data : data,
     success : function(data) {
     setGridCell(i, colName, data.msg);
     }
     });
     setGridCell(i, colName, "loadding...");
     findBizResult(bizId);
     } */
</script>
<body>
<div id="businessModelDataTable"></div>
</body>
</html>
